package day2;

/**
 * ClassName：Test2
 *
 * @Author：小鱼
 * @Create：2025-08-19 10:26
 */
public class Test2 {
    public static void main(String[] args) {
      Thread thread =  new Thread("MyThread"){
            //匿名内部类
            @Override
            public void run(){
                for (int i = 0; i < 10; i++) {
                    System.out.println("在线程的run中");
                    try {
                        //这个方法有异常
                        Thread.sleep(10);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println("i: "+i);
                }
            }
        };
        thread.start();
        String name = thread.getName();
        System.out.println(name);

        thread.setName("MyThread_new");
        String name1 = thread.getName();
        System.out.println(name1);


        //获取当前线程对象
        Thread threadMain = Thread.currentThread();
        System.out.println(threadMain.getName());
    }
}
